<template>
	<view>
		<view class="header status_bar">
			<view class="back iconfont" @tap="backPage">&#xe779;</view>
			<view class="text">选择车系</view>
		</view>
		<view class="clear_box"></view>

		<block v-for="(item, index) in obtainCitys">
			<view class="brand_box">
				<view class="brand">{{item.name}}</view>
				<block v-for="(item02, index02) in item.child">
					<view class="name" @click="cityClick(item02)">
						<view class="n">{{item02.name}}</view>
						<view class="a iconfont icon-xiangyou1"></view>
					</view>
				</block>
			</view>
		</block>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				obtainCitys: [],
				handleCity: [],
				type:0,
				brand_id:-1,
			}
		},
		onLoad(e) {
			if (e.type) {
				this.type = e.type;
			}
			this.brand_id = e.brand_id;
			//动态更新数据
			this.loadData();
		},
		methods: {
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				this.$r(url);
			},
			loadData() {
				let that = this;
				that.Net._get('other/get_brand_child', {brand_id:that.brand_id}, res => {
					if (res.code == 1) {
						that.obtainCitys = res.data;
						// console.log(that.obtainCitys)
					}
				});
			},
			hasDuplicateProperty(array, property) {
				const values = array.map(item => item[property]);
				return new Set(values).size !== new Set(array).size;
			},
			cityIndexPosition(letter) {
				if (!letter) {
					return ''
				}
				const ACode = 65
				return letter === '#' ? 26 : letter.charCodeAt(0) - ACode
			},
			cityClick(item) {
				console.log(this.type)
				if (this.type == 1) {
					uni.$emit('get_brand_p', item)
				} else {
					uni.$emit('get_brand', item)
				}
				setTimeout(() => {
					uni.navigateBack({
					    delta: 2  // 返回的页面层数，2 表示返回两级
					});
					/* uni.switchTab({
						url: 'pages/index/index',
					}); */
					// uni.navigateBack({});
				}, 300)

			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}

	.brand_box {
		width: 92%;
		margin: 0 auto;
		margin-top: 4vw;
	}

	.brand_box .brand {
		width: 100%;
		height: 8vw;
		line-height: 8vw;
		color: #999;
		font-size: 3.5vw;
		border-bottom: 1px solid #EEEEEE;
	}

	.brand_box .name {
		width: 100%;
		height: 10vw;
		border-bottom: 1px solid #EEEEEE;
		display: flex;
		align-items: center;
	}

	.brand_box .name .n {
		font-size: 3.5vw;
		color: #333;
	}

	.brand_box .name .a {
		flex: 1;
		text-align: right;
		font-size: 4vw;
		color: #666;
	}
</style>